package com.rgz.controller.wgController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.rgz.mapper.AdressMapper;
import com.rgz.mapper.AdressThreeMapper;
import com.rgz.mapper.AdressTwoMapper;
import com.rgz.pojo.Adress;
import com.rgz.pojo.AdressThree;
import com.rgz.pojo.AdressThreeExample;
import com.rgz.pojo.AdressTwo;
import com.rgz.pojo.AdressTwoExample;
import com.rgz.pojo.AdressTwoExample.Criteria;

@Controller
public class AdressController {
	@Autowired
	private AdressMapper adressMapper;
	@Autowired
	private AdressTwoMapper adressTwoMapper;
	@Autowired
	private AdressThreeMapper adressThreeMapper;
	@RequestMapping("adress")
	public String Adress(){
		return "adress";
	}
	
	@RequestMapping(value="/ProvinceServlet",produces="application/json;charset=utf-8")
	@ResponseBody
	public String ProvinceServlet(){
		List<Adress> Province = adressMapper.selectByExample(null);
		String Provinces = JSON.toJSONString(Province);
		return Provinces;
	}
	@RequestMapping(value="/CityServlet",produces="application/json;charset=utf-8")
	@ResponseBody
	public String CityServlet(Integer proId){
		AdressTwoExample adressTwoExample = new AdressTwoExample();
		Criteria criteria = adressTwoExample.createCriteria();
		criteria.andAdressidEqualTo(proId);
		List<AdressTwo> adressTwo = adressTwoMapper.selectByExample(adressTwoExample);
		String adressTwos = JSON.toJSONString(adressTwo);
		return adressTwos;
	}
	
	
	@RequestMapping(value="/CountyServlet",produces="application/json;charset=utf-8")
	@ResponseBody
	public String CountyServlet(Integer cityId){
		AdressThreeExample adressThreeExample = new AdressThreeExample();
		com.rgz.pojo.AdressThreeExample.Criteria createCriteria = adressThreeExample.createCriteria();
		createCriteria.andTwoidEqualTo(cityId);
		List<AdressThree> adressThree = adressThreeMapper.selectByExample(adressThreeExample);
		String adressThrees = JSON.toJSONString(adressThree);
		return adressThrees;
	}
	@RequestMapping(value="/company",produces="application/json;charset=utf-8")
	@ResponseBody
	public String company(){
		List<AdressThree> adressThree = adressThreeMapper.selectByExample(null);
		String adressThrees = JSON.toJSONString(adressThree);
		return adressThrees;
	}
	
	@RequestMapping(value="/soso",produces="application/json;charset=utf-8")
	@ResponseBody
	public String soso(Integer city,String adress){
		
		System.out.println("city"+city+"==="+adress);
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("city", city);
		map.put("adress", adress);
		List<AdressThree> soso = adressThreeMapper.soso(map);
		for (AdressThree adressThree : soso) {
			System.out.println(adressThree);
		}
		String adressThrees = JSON.toJSONString(soso);
		return adressThrees;
	}
	
	
}
